﻿using System;
using System.Collections.Generic;

namespace CAION2.Classes
{
    using System.Data;
    using System.Globalization;

    using Models;

    public class RandomBonus
    {
        public byte Id { get; set; }
        public string Chance { get; set; }
        public List<KeyValuePair<string, float>> RandomBonuses { get; set; }

        public RandomBonus(DataRow row)
        {
            CreateRandomBonus(row);
        }

        public RandomBonus(string id, string name)
        {
            DataRow row = DataModel.GetRow("Random_Options", string.Format("name = '{0}' AND attr_group_id = '{1}'", name, id));
            CreateRandomBonus(row);
        }

        private void CreateRandomBonus(DataRow row)
        {
            if (row == null) return;

            Id = Convert.ToByte(row["attr_group_id"]);
            Chance = (Convert.ToInt16(row["prob"]) / 100).ToString(CultureInfo.InvariantCulture) + "%";

            RandomBonuses = new List<KeyValuePair<string, float>>();

            for (int i = 1; i <= 8; i++)
            {
                if (string.IsNullOrEmpty(row["random_attr" + i].ToString())) continue;
                KeyValuePair<string, float> random = CardStat.GetStat(row["random_attr" + i].ToString());
                RandomBonuses.Add(new KeyValuePair<string, float>(random.Key, random.Value));
            }
        }
    }
}
